package demo5;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;

public class Test {
    public static void main(String[] args) {
        //1.给10个数据,找出第一个重复的值
        int[]array  ={1,2,3,2,3,6,7,8,9,10};
      /*  HashSet<Integer> set = new HashSet<>();
        for (int x : array){
            if (!set.contains(x)) {
                set.add(x);
            }else {
                System.out.println(x);
                return;
            }
        }
*/
//2.给10个数据,去重
        HashSet<Integer> set = new HashSet<>();
        for (int x : array){
                set.add(x);
        } System.out.println(set);

        //3.给10个数据,重复数据出现的次数
        Map<Integer,Integer> map = new HashMap<>();
        for (int i = 0; i < array.length; i++) {
            if(map.get(array[i])== null){
                map.put(array[i],1);

            }else {
                int val = map.get(array[i]);
                map.put(array[i],val+1);
            }

        }
        for(Map.Entry<Integer,Integer> entry : map.entrySet()){
            System.out.println("数字 :" +entry.getKey()+"次数:"+entry.getValue());
        }





    }
}
